<?php

namespace Modules\Collage\Http\Controllers;

use Catch\Base\CatchController as Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Modules\Collage\Models\Guide;

class GuideController extends Controller
{
    public function __construct(
        protected readonly Guide $model
    ) {
    }

    /**
     * @return mixed
     */
    public function index(): mixed
    {
        return $this->model->setBeforeGetList(function ($query) {
            return $query->orderByDesc('sort');
        })->getList();
    }

    /**
     * @param Request $request
     * @return mixed
     */
    public function store(Request $request)
    {
        return $this->model->storeBy($request->all());
    }

    /**
     * @param $id
     * @return \Illuminate\Database\Eloquent\Model|null
     */
    public function show($id)
    {
        $banner = $this->model->firstBy($id);


        return $banner;
    }

    /**
     * @param $id
     * @param Request $request
     * @return true
     */
    public function update($id, Request $request)
    {
       return $this->model->updateBy($id, $request->all());
    }

    /**
     * 删除
     */
    public function destroy($id): bool
    {
        return $this->model->deletesBy($id);
    }

    /**
     * enable
     */
    public function enable($id): bool
    {
        return $this->model->togglesBy($id);
    }
}
